package com.life.muyu.controller;

import com.life.muyu.dto.MailRecordsDTO;
import com.life.muyu.dto.ResultDTO;
import com.life.muyu.exception.CustomizeErrorCode;
import com.life.muyu.model.MailSubscriber;
import com.life.muyu.service.ExpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author zyb
 * @Date 2020-04-01 4:18 PM
 **/
@Controller
public class ExpressController {

    @Autowired
    private ExpressService expressService;

    @GetMapping("/express")
    public String toExpress(){
        return "express";
    }

    @GetMapping("/managerExpress")
    public String toManExpress(){
        return "express/express";
    }

    @PostMapping("/getSubscriber")
    @ResponseBody
    public Object getSubscriber(){
        return ResultDTO.okof(expressService.list());
    }

    @PostMapping("/getMailSendRecords")
    @ResponseBody
    public Object getSubscriberRecords(){
        return ResultDTO.okof(expressService.getMailSendRecords());
    }

    @PostMapping("/addSubscriber")
    @ResponseBody
    public Object addExpress(@RequestParam("mail") String mailAddr){
        expressService.save(MailSubscriber.builder().mailSubscriberAddr(mailAddr).build());
        return ResultDTO.okof(CustomizeErrorCode.SUCCESS);
    }

}
